package exe4;

import java.util.Arrays;

public class Company {
    String name;//公司名称
    String phone;//公司电话
    String address;//公司地址
    Yuangong woker[] = new Yuangong[30];//员工
    int count = 0;//员工个数

    public Company(String name, String phone, String address) {
        this.name = name;
        this.phone = phone;
        this.address = address;
    }

    //增加员工；
    public boolean add(Yuangong c) {
        if (count >= woker.length) {
            System.out.println("已满");
            return false;
        }
        woker[count++] = c;
        return true;
    }

    //显示员工信息
    public void show1() {
        for (int i = 0; i < count; i++) {
            woker[i].show();
        }
    }

    //辞退员工
    public void citui(int no) {
        for (int i = 0; i < count; i++) {
            if (no == woker[i].no) {
                for (int j = i; j < count - 1; j++) {
                    woker[j] = woker[j + 1];

                }
                woker[--count] = null;//原位置为空

                return;
            }
        }
    }

    //找最高薪水
    public Yuangong findTopSalary() {
        Yuangong max = woker[0];
        for (int i = 0; i < count; i++) {
            if (woker[i].xinshui > max.xinshui) {
                max = woker[i];
            }
        }
        return max;
    }

    //薪水从高到低排序
    public void sortBySalDesc() {
        if (count == 0) {
            return;
        }
        double[] arr = new double[count];
        for (int i = 0; i < count; i++) {
            arr[i] = woker[i].xinshui;
        }
        double temp;
        for (int j = 0; j < count; j++)
            for (int i = count - 1; i > j; i--) {
                if (arr[i] > arr[i - 1]) {
                    temp = arr[i - 1];
                    arr[i - 1] = arr[i];
                    arr[i] = temp;
                }

            }
        System.out.println("薪水从高到低排序");
        for (int i = 0; i < count; i++) {
            System.out.println(arr[i] + "元  ");

        }
    }


}
